package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysAuditLog;
import com.ruoyi.system.service.ISysAuditLogService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 审核日志Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/audit")
public class SysAuditLogController extends BaseController
{
    @Autowired
    private ISysAuditLogService sysAuditLogService;

    /**
     * 查询审核日志列表
     */
    @RequiresPermissions("system:log:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAuditLog sysAuditLog)
    {
        startPage();
        List<SysAuditLog> list = sysAuditLogService.selectSysAuditLogList(sysAuditLog);
        return getDataTable(list);
    }

    /**
     * 导出审核日志列表
     */
    @RequiresPermissions("system:log:export")
    @Log(title = "审核日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAuditLog sysAuditLog)
    {
        List<SysAuditLog> list = sysAuditLogService.selectSysAuditLogList(sysAuditLog);
        ExcelUtil<SysAuditLog> util = new ExcelUtil<SysAuditLog>(SysAuditLog.class);
        util.exportExcel(response, list, "审核日志数据");
    }

    /**
     * 获取审核日志详细信息
     */
    @RequiresPermissions("system:log:query")
    @GetMapping(value = "/{auditlogId}")
    public AjaxResult getInfo(@PathVariable("auditlogId") Long auditlogId)
    {
        return success(sysAuditLogService.selectSysAuditLogByAuditlogId(auditlogId));
    }

    /**
     * 新增审核日志
     */
    @RequiresPermissions("system:log:add")
    @Log(title = "审核日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAuditLog sysAuditLog)
    {
        return toAjax(sysAuditLogService.insertSysAuditLog(sysAuditLog));
    }

    /**
     * 修改审核日志
     */
    @RequiresPermissions("system:log:edit")
    @Log(title = "审核日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAuditLog sysAuditLog)
    {
        return toAjax(sysAuditLogService.updateSysAuditLog(sysAuditLog));
    }

    /**
     * 删除审核日志
     */
    @RequiresPermissions("system:log:remove")
    @Log(title = "审核日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{auditlogIds}")
    public AjaxResult remove(@PathVariable Long[] auditlogIds)
    {
        return toAjax(sysAuditLogService.deleteSysAuditLogByAuditlogIds(auditlogIds));
    }
}
